<html>

<head>
  <meta charset="utf-8">
  <title>药品入库或使用登记</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top:20px">
  <legend style="margin:0px auto">药品入库或使用登记单</legend>
</fieldset>



<form class="layui-form" style="width:1200px;margin:0px auto">
  <div class="layui-form-item">
    <label class="layui-form-label">登记时间<span style="color:red">*</span></label>
    <div class="layui-input-inline">
      <input type="text" name="date" lay-verify="required" class="layui-input" id="date" placeholder="请选择日期">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">选择功能<span style="color:red">*</span></label>
    <div class="layui-input-inline">
      <select name="function" id="function" title="">
        <option value="药品使用" selected="">药品使用</option>
        <option value="药品入库">药品入库</option>
      </select>
    </div>
  </div>

  <div class="layui-form-item">

    <div class="layui-inline">
      <label class="layui-form-label">药品名称<span style="color:red">*</span></label>
      <div class="layui-input-block">
        <input type="text" name="drugName" id="drugName" lay-verify="required" class="layui-input" style="position:absolute;z-index:2;width:80%;" placeholder="请输入或选择药品名称"  autocomplete="off">
        <select id ="drugNameSearch" lay-filter="drugNameSearch" lay-search="">
          <option value="">直接选择或者搜索选择</option>
          {% for drug in drugs %}
          <option value="{{drug.drugName}}">{{drug.drugName}}</option>
          {% endfor %}
        </select>
       </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">药品CAS号<span style="color:red">*</span></label>
      <div class="layui-input-block">
        <input type="text" name="drugCAS" id="drugCAS" lay-verify="required" class="layui-input" style="position:absolute;z-index:2;width:80%;" placeholder="请输入或选择药品CAS号" autocomplete="off">
        <select id="drugCASSearch" lay-filter="drugCASSearch" lay-search="">
        <option value="">直接选择或者搜索选择</option>
        {% for drug in drugs %}
        <option value="{{drug.drugCAS}}">{{drug.drugCAS}}</option>
        {% endfor %}
      </select>
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">药品安全性<span style="color:red">*</span></label>
      <div class="layui-input-block">
        <select name="drugSafetyDegree" title="">
          <option value="一般药品" selected="">一般药品</option>
          <option value="危化品">危化品</option>
        </select>
       </div>
    </div>

  </div>

  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">数量<span style="color:red">*</span></label>
      <div class="layui-input-inline">
        <input type="text" name="drugAmount" lay-verify="required" class="layui-input" placeholder="请输入数量">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">单位<span style="color:red">*</span></label>
      <div class="layui-input-inline">
        <select name="drugUnit" title="">
          <option value="瓶" selected="">瓶</option>
          <option value="克">克（g）</option>
          <option value="千克">千克（Kg）</option>
          <option value="毫升">毫升（mL）</option>
          <option value="升">升（L）</option>
        </select>
      </div>
    </div>

  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">备注</label>
    <div class="layui-input-block">
      <textarea name="note" placeholder="" class="layui-textarea"></textarea>
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>

</form>



<script src="../../static/layui/layui.js" charset="utf-8"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>

layui.use(['laydate', 'layer', 'form'], function(){
  var laydate = layui.laydate;
  var layer = layui.layer,$ = layui.jquery,form = layui.form;
  //直接嵌套显示
  laydate.render({
    elem: '#date'
  });
  form.on('select(drugNameSearch)', function(data){
    document.getElementById("drugName").setAttribute('value', $("#drugNameSearch option:selected").text());
  });
  form.on('select(drugCASSearch)', function(data){
    document.getElementById("drugCAS").setAttribute('value', $("#drugCASSearch option:selected").text());
  });
  form.on('submit', function(data) {
    $.ajax({
        url:"{% url 'student:drug-check-update' %}",
        data: data.field,
        dataType:'json',
        type:'post',
        success:function(data) {
          if (data.code === 1){
            layer.msg('添加失败');
          }else if (data.code === 0){
            layer.msg('添加成功');
          }
          setTimeout(function() {
                location.href = location.href;
            }, 500);
        }
    });
    return false;
  });

});
</script>
</body>
</html>